﻿using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Target = KC.Business.Graphics;

namespace KC.Tests.Business.Graphics
{
	[TestClass]
	public class Management : Target.Management
	{
		private const string ValidImageFile = @"C:\tfs\tfs09.codeplex.com\KcArchitecture\KC Architecture 2\trunk\_Overhead\KC.Tests\References\spacewalk.jpg";
		private readonly string
			InvalidImageFile = @"c:\" + System.DateTime.Now.Ticks.ToString() + "_" + new Random().Next(0, Int32.MaxValue).ToString() + ".jpg",
			ThumbnailFile = Path.GetTempFileName();
		private const int ThumbnailX = 400;

		[TestMethod]
		[TestCategory("Unit")]
		public void CreateThumbnailTest()
		{
			CreateThumbnail(ValidImageFile, ThumbnailFile, ThumbnailX);
			Assert.IsTrue(File.Exists(ThumbnailFile));

			using (System.Drawing.Image img = System.Drawing.Image.FromFile(ThumbnailFile))
				Assert.AreEqual(img.Width, ThumbnailX);
		}
		[TestMethod]
		[TestCategory("Unit")]
		[ExpectedException(typeof(ArgumentNullException))]
		public void CreateThumbnailNullTest1()
		{
			CreateThumbnail(null, ThumbnailFile, ThumbnailX);
		}
		[TestMethod]
		[TestCategory("Unit")]
		[ExpectedException(typeof(ArgumentNullException))]
		public void CreateThumbnailNullTest2()
		{
			CreateThumbnail(ValidImageFile, null, ThumbnailX);
		}
		[TestMethod]
		[TestCategory("Unit")]
		[ExpectedException(typeof(ArgumentOutOfRangeException))]
		public void CreateThumbnailRangeTest()
		{
			CreateThumbnail(ValidImageFile, ThumbnailFile, 1);
		}
		[TestMethod]
		[TestCategory("Unit")]
		[ExpectedException(typeof(FileNotFoundException))]
		public void CreateThumbnailBogusFileTest()
		{
			CreateThumbnail(InvalidImageFile, ThumbnailFile, ThumbnailX);
		}

		[TestCleanup]
		public void Cleanup()
		{ if (File.Exists(ThumbnailFile)) System.IO.File.Delete(ThumbnailFile); }

	}
}
